package com.xiaoyushu.note.biz.rpc;

import com.xiaoyushu.framework.common.response.Response;
import com.xiaoyushu.user.api.UserFeignApi;
import com.xiaoyushu.user.dto.req.FindUserByIdReqDTO;
import com.xiaoyushu.user.dto.resp.FindUserByIdRspDTO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

import java.util.Objects;

@Component
public class UserRpcService {
    @Resource
    private UserFeignApi userFeignApi;

    /**
     * 查询用户信息
     * @param id
     * @return
     */
    public FindUserByIdRspDTO findById(Long id) {
        FindUserByIdReqDTO findUserByIdReqDTO = new FindUserByIdReqDTO();
        findUserByIdReqDTO.setId(id);
        Response<FindUserByIdRspDTO> byId = userFeignApi.findById(findUserByIdReqDTO);
        if (Objects.isNull(byId) || !byId.isSuccess()){
            return null;
        }

        return byId.getData();
    }
}
